package com.spzx.product;

import com.spzx.common.security.annotation.EnableCustomConfig;
import com.spzx.common.security.annotation.EnableRyFeignClients;
import com.spzx.product.api.domain.ProductSku;
import com.spzx.product.mapper.ProductSkuMapper;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.List;

/**
 * 商品模块
 */
@EnableCustomConfig
@EnableRyFeignClients
@SpringBootApplication
public class SpzxProductApplication implements CommandLineRunner
{
    public static void main(String[] args)
    {
        SpringApplication.run(SpzxProductApplication.class, args);
        System.out.println("(♥◠‿◠)ﾉﾞ  系统模块启动成功   ლ(´ڡ`ლ)ﾞ  \n" +
                " .-------.       ____     __        \n" +
                " |  _ _   \\      \\   \\   /  /    \n" +
                " | ( ' )  |       \\  _. /  '       \n" +
                " |(_ o _) /        _( )_ .'         \n" +
                " | (_,_).' __  ___(_ o _)'          \n" +
                " |  |\\ \\  |  ||   |(_,_)'         \n" +
                " |  | \\ `'   /|   `-'  /           \n" +
                " |  |  \\    /  \\      /           \n" +
                " ''-'   `'-'    `-..-'              ");
    }

    @Autowired
    RedissonClient redissonClient;

    //@Autowired
    //ProductSkuMapper productSkuMapper;

    //Springboot应用初始化后会执行一次该方法
    @Override
    public void run(String... args) throws Exception {
        RBloomFilter<Object> bloomFilter = redissonClient.getBloomFilter("sku:bloom:filter");//借助于redis实现布隆过滤器的。因为Redis中有位图（Bitmap）
        bloomFilter.tryInit(10000,0.01); //初始化布隆过滤器：设置数据量大小，误判率。

        //启动为了测试一下布隆过滤器数据初始化。临时代码。
        /*List<ProductSku> productSkuList = productSkuMapper.selectList(null);
        productSkuList.forEach(productSku -> {
            bloomFilter.add(productSku.getId()); //假设3个hash函数，对每一个skuId进行hash函数计算，将对应索引的位置二进制位设置成1.
        });*/
    }
}